/**
 * Created by zhengjiachao on 2017/5/15.
 */

BCP.bill.modalRenderer.SubtableModalRenderer = function(){
    BCP.bill.modalRenderer.SubtableModalRenderer.superclass.constructor.call(this);
};

BCP.bill.modalRenderer.SubtableModalRenderer.ID = "bcpSubtableModalRenderer";

COM.util.defineClass(BCP.bill.modalRenderer.SubtableModalRenderer, ADF.modalRenderer.BaseModalRenderer,{
    
    _getTitle : function(){
        return '子表设计';
    },
    _renderBody  : function(parentDom, contentData){
        var kclass = window.BCP.bill._bindings_.kclass;
        var attrs = [];
        var attrObjs = [];
        if(kclass){
            var arr = kclass.attArr;
            for (var i = 0; i < arr.length; i++) {
                var element = arr[i];
                if(element.type.indexOf("[]") >= 0){
                    attrs.push(element);
                }
            }
            var length = attrs.length;
            var that = this;
            for (var j = 0; j < attrs.length; j++) {
                var attr = attrs[j];
                if(window.semantic_object_manager){
                    semantic_object_manager.findSemanticObject(attr.type.substring(0, attr.type.indexOf("[]"))).then(function (semanticObject) {
                        attrObjs.push(semanticObject);
                        length--;
                        if(length === 0){
                            that.__renderBody(parentDom, contentData, attrs, attrObjs);
                        }
                    }).catch(function (e) {
                        console.error(e);
                    });
                }
            }
        }else{
            //为了实现本地运行效果与enzyme平台效果一直，而自定义数据
            attrs = [{title:'子表1',name:'subdatas'},{title:'子表2',name:'name2'}];
            attrObjs = [{attArr:[{type:'string',title:'字符',name:'string'},{type:'datetime',title:'日期',name:'createTime'},{type:'number',title:'数字',name:'number'},{type:'boolean',title:'布尔',name:'boolean'},{type:'int',title:'整数',name:'int'},{type:'float',title:'浮点数',name:'float'}]},{attArr:[{type:'string',title:'字符',name:'string'},{type:'number',title:'数值',name:'number'}]}];
            this.__renderBody(parentDom,contentData,attrs,attrObjs);
        }
    }, 
    __renderBody : function(parentDom, contentData, attrs, attrObjs){
        parentDom.innerHTML = '\
        <div style="width: 100%;height: 556px;">\
            <div style="width: 100%;height: 35px;padding: 6px 0;position:relative">\
            <div class="changeFont" style="width: 14%;height: 22px;border: 1px solid #e5e5e5;display: inline-block;">\
            <input type="text" readonly value="宋体" style="border: none;outline: none;width: 84%;padding: 0;"/>\
            <span style="display: inline-block;right: 3px;top: 3px;" class="glyphicon glyphicon-chevron-down"></span>\
            </div>\
            <div class="changeFontC" style="position:absolute;width:14%;display:none;z-index:1000;top:28px;height:200px;">\
            <ul style="overflow:auto;border:1px solid #ddd;background-color:#fff;"></ul>\
            </div>\
            <div class="changeFontSize" style="border: 1px solid #e5e5e5;height: 22px;width: 7%;display: inline-block;">\
            <input type="text" readonly value="14" style="border: none;outline: none;width: 68%;padding: 0"/>\
            <span style="display: inline-block;top: 3px;right:3px;" class="glyphicon glyphicon-chevron-down"></span>\
            </div>\
            <div class="changeFontSizeC" style="position:absolute;width:7%;display:none;z-index:1000;top:28px;height:200px;left:-webkit-calc(14% + 4px);left:-moz-calc(14% + 4px);left:calc(14% + 4px);">\
            <ul style="overflow:auto;border:1px solid #ddd;background-color:#fff;"></ul>\
            </div>\
            <button class="btn btn-default font_bold" type="button" style="padding: 2px 8px;border: none;" title="文字加粗">\
            <span class="glyphicon glyphicon-bold"></span>\
            </button>\
            <button class="btn btn-default font_italic" type="button" style="padding: 2px 8px;border: none;" title="文字倾斜">\
            <span class="glyphicon glyphicon-italic"></span>\
            </button>\
            <button class="btn btn-default text_decoration" type="button" style="padding: 2px 8px;border: none;" title="下划线">\
            <span>下划线</span>\
            </button>\
            <input class="ftCustom"/>\
            <button class="btn btn-default" type="button" style="padding: 2px 8px;border: none;" title="格式刷">\
            <span class="glyphicon glyphicon-erase"></span>\
            </button>\
            <button class="btn btn-default align_left" type="button" style="padding: 2px 8px;border: none;" title="文字居左">\
            <span class="glyphicon glyphicon-align-left"></span>\
            </button>\
            <button class="btn btn-default align_center" type="button" style="padding: 2px 8px;border: none;" title="文字水平居中">\
            <span class="glyphicon glyphicon-align-center"></span>\
            </button>\
            <button class="btn btn-default align_right" type="button" style="padding: 2px 8px;border: none;" title="文字居右">\
            <span class="glyphicon glyphicon-align-right"></span>\
            </button>\
            <button class="btn btn-default textVertical" type="button" style="padding:2px 8px;display:inline-block;border: none;position:relative;z-index:1001;border:none;outline:none;background-color:#fff;" title="文本垂直对齐方式">\
            <span class="glyphicon glyphicon-align-justify"></span>\
            <span class="glyphicon glyphicon-triangle-bottom"></span>\
            </button>\
            <div class="textVerticalC btn-group-vertical" style="position:absolute;z-index:1000;border:1px solid #ccc;top:27px;right:-webkit-calc(32% + 2px);right:-moz-calc(32% + 2px);right:calc(32% + 2px);display:none;">\
            <button type="button" class="btn btn-default vertical_top" style="border:none;">\
            <span>顶端对齐</span>\
            </button>\
            <button type="button" class="btn btn-default vertical_middle" style="border:none;">\
            <span>垂直居中</span>\
            </button>\
            <button type="button" class="btn btn-default vertical_bottom" style="border:none;">\
            <span>底端对齐</span>\
            </button>\
            </div>\
            <input class="bgCustom"/>\
            <button class="btn btn-default mergeCell" type="button" style="padding:2px 8px;border:none;" title="合并单元格">\
            <span>合并</span>\
            </button>\
            <button class="btn btn-default tableBorder" type="button" style="padding:2px 8px;border:none;position:relative;z-index:1005;background-color:#fff;outline:none;" title="表格边框">\
            <span class="tableBorderShow">边框</span>\
            <span class="glyphicon glyphicon-triangle-bottom"></span>\
            </button>\
            <div class="tableBorderC btn-group-vertical" style="position:absolute;z-index:1002;border:1px solid #ccc;top:27px;right:webkit-calc(11% + 9px);right:-moz-calc(11% + 9px);right:calc(11% + 9px);display:none;">\
            <button class="btn btn-default allTableBorder tableBorderSelected" type="button" style="border:none;"><span>所有框线</span></button>\
            <button class="btn btn-default outTableBorder" type="button" style="border:none;"><span>外侧框线</span></button>\
            <button class="btn btn-default innerTableBorder" type="button" style="border:none;"><span>内部框线</span></button>\
            <button class="btn btn-default rowTableBorder" type="button" style="border:none;"><span>内部横框线</span></button>\
            <button class="btn btn-default colTableBorder" type="button" style="border:none;"><span>内部竖框线</span></button>\
            <button class="btn btn-default upTableBorder" type="button" style="border:none;"><span>上框线</span></button>\
            <button class="btn btn-default downTableBorder" type="button" style="border:none;"><span>下框线</span></button>\
            <button class="btn btn-default leftTableBorder" type="button" style="border:none;"><span>左框线</span></button>\
            <button class="btn btn-default rightTableBorder" type="button" style="border:none;"><span>右框线</span></button>\
            <button class="btn btn-default noTableBorder" type="button" style="border:none;"><span>无框线</span></button>\
            </div>\
            <button class="btn btn-default changeMore" type="button" style="padding:2px 8px;position:relative;z-index:1001;border:none;background-color:#fff;outline:none;">\
            <span>更多</span>\
            <span class="glyphicon glyphicon-triangle-bottom"></span>\
            </button>\
            <div class="changeMoreC btn-group-vertical" style="position:absolute;right:-webkit-calc(6% - 1px);right:-moz-calc(6% - 1px);right:calc(6% - 1px);top:27px;border:1px solid #ccc;z-index:1000;display:none;">\
            <button class="btn btn-default bulge" type="button" style="border:none;">\
            <span>凸起</span>\
            </button>\
            <button class="btn btn-default lineWrap" type="button" style="border:none">\
            <span>折行</span>\
            </button>\
            <button class="btn btn-default writing_mode" type="button" style="border:none">\
            <span>竖向文字</span>\
            </button>\
            </div>\
            </div>\
            <div style="width: 100%;height: 35px;margin-top: 2px;padding: 6px 0">\
            <button class="btn btn-default upRow" type="button" style="padding: 0 8px;border: none" title="上插行">\
            <span class="glyphicon glyphicon-object-align-top"></span>\
            </button>\
            <button class="btn btn-default downRow" type="button" style="padding: 0 8px;border: none;" title="下插行">\
            <span class="glyphicon glyphicon-object-align-bottom"></span>\
            </button>\
            <button class="btn btn-default disabled leftCol" type="button" style="padding:0 8px;border:none;" title="左插列">\
            <span>左插列</span>\
            </button>\
            <button class="btn btn-default rightCol" type="button" style="padding:0 8px;border:none;" title="右插列">\
            <span>右插列</span>\
            </button>\
            <button class="btn btn-default removeRow" type="button" style="padding:0 8px;border:none;">\
            <span>删行</span>\
            </button>\
            <button class="btn btn-default removeCol disabled" type="button" style="padding:0 8px;border:none;">\
            <span>删列</span>\
            </button>\
            <button class="btn btn-default setFloatRow" type="button" style="padding:0 8px;border:none;" title="设置浮动">\
            <span>浮动</span>\
            </button>\
            <button class="btn btn-default EditFloatRow" type="button" style="padding:0 8px;border:none;" title="浮动行设置">\
            <span>设置</span>\
            </button>\
            <button class="btn btn-default lockCol" type="button" style="padding:0 8px;border:none;" title="锁定列">\
            <span>锁定列</span>\
            </button>\
            <label style="margin-left: 5px">列数：</label>\
            <div style="border: 1px solid #e5e5e5;height: 22px;width: 7%;display: inline-block;">\
            <input oncontextmenu="return false" class="colNumber" value="1" type="text" style="border: none;outline: none;width:100%;"/>\
            </div>\
            <label style="margin-left: 5px">行高：</label>\
            <div style="border: 1px solid #e5e5e5;height: 22px;width: 7%;display: inline-block;">\
            <input oncontextmenu="return false" class="rowNumber" type="text" style="border: none;outline: none;width:100%;"/>\
            </div>\
            <label style="margin-left: 5px">列宽：</label>\
            <div style="border: 1px solid #e5e5e5;height: 22px;width: 8%;display: inline-block;">\
            <input oncontextmenu="return false" class="colWidth" type="text" style="border: none;outline: none;width:100%;"/>\
            </div>\
            </div>\
            <div style="margin-top: 10px">\
            <div style="width: 22%;float: left;margin-right: 10px;position:relative">\
            <div class="clickSelectList" style="border: 1px solid #e5e5e5;height: 22px;margin-bottom: 5px;">\
            <input style="border: none;width: 82%;outline: none;text-indent: 5px;padding: 0" type="text"/>\
            <span style="display: inline-block;left: 7px;top: 3px" class="glyphicon glyphicon-chevron-down"></span>\
            </div>\
            <div class="selectList" style="width:100%;position:absolute;z-index:55555;display:none;overflow:auto;height:450px;">\
            <ul class="list-group">\
            </ul>\
            </div>\
            <div style="border: 1px solid #e5e5e5;height: 25px;margin-bottom: 5px;">\
            <input style="border: none;width: 82%;outline: none;text-indent: 5px;padding: 0;" type="text"/>\
            <span style="display: inline-block;left: 7px;top: 3px" class="glyphicon glyphicon-search"></span>\
            </div>\
            <div style="border: 1px solid #e5e5e5;height: 413px;overflow:auto;" class="selectListC">\
            </div>\
            </div>\
            <div style="width: 76.5%;height:470px;float: right;border: 1px solid #e5e5e5">\
            <div class="tableContent">\
            <div class="tableChild class="col-lg-12"></div>\
            </div>\
            </div>\
            </div>\
            </div>';

        var $listUl = $(parentDom).find(".selectList ul");
        var $listContainer = $(parentDom).find(".selectListC");

        //同步数据库数据到字表界面
        if(attrs){
            for (var i = 0; i < attrs.length; i++) {
                var element = attrs[i];
                $listUl.append('<li class="list-group-item" _name="' + element.name + '">' + element.title + '</li>');
            }
            $($listUl.children()[0]).addClass("listSelected");
        }
        if(attrObjs){
            for (var i = 0; i < attrObjs.length; i++) {
                var element = attrObjs[i];
                var $ul = $('<ul class="list-group hide_listSelected"></ul>');
                $listContainer.append($ul);
                for (var j = 0; j < element.attArr.length; j++) {
                    var subAttr = element.attArr[j];
                    $ul.append('<li class="list-group-item" _type="' + subAttr.type + '"><span class="thListValue">' + subAttr.title + '</span>(<span class="tdListValue">' + subAttr.name + '</span>)</li>');
                }
            }
            $($listContainer.children()[0]).addClass("show_listSelected").removeClass('hide_listSelected');
        }

        //为指定块级元素，初始化创建表格
         var tableChild = $('.tableChild').toCreateZcTable({});
         //表格反序列化
         tableChild.setSerialize(contentData.tableData);
        //设置表格不可编辑
        tableChild.setTrNotSelect("true");

        //选择子表：每选择一次子表都会反序列化表格
        var listFlag = true;
        var selectListValue = $(".selectList .listSelected").text();
        $(".clickSelectList input").val(selectListValue);
        $(".clickSelectList").click(function(){
            if(listFlag == true){
                $(".selectList").css('display','block');
                listFlag = false;
            }else{
                $(".selectList").css('display','none');
                listFlag = true;
            }
        });
        $(".selectList li").click(function(){
            var listValue = $(this).text();
            var clickSelectValue = $(".clickSelectList input").val();
            if(listValue!=clickSelectValue){
                var confirmValue = confirm('一个表格只能选择一个子表，你确认选择这个表格吗？');
                if(confirmValue){
                    $(".clickSelectList input").val(listValue);
                    var index = $(this).index();
                    $(".selectList li").removeClass("listSelected");
                    $(this).addClass("listSelected");
                    $(".selectListC ul").removeClass("show_listSelected");
                    $(".selectListC ul").addClass("hide_listSelected");
                    $(".selectListC ul").eq(index).removeClass("hide_listSelected");
                    $(".selectListC ul").eq(index).addClass("show_listSelected");
                    $(".selectList").css('display','none');
                    listFlag = true;
                    tableChild.setSerialize(contentData.tableData);
                    $("button").removeClass('active');
                    $(".leftCol").addClass('disabled');
                }else{
                    $(".selectList").css('display','none');
                    listFlag = true;
                }
            }else{
                $(".selectList").css('display','none');
                listFlag = true;
            }

        });

        //拖拽子表字段
        $(".selectListC ul li").mousedown(function(e){
            //确定拖动元素坐标位置
            var offsetValue = $(".selectListC").offset();
            var x = e.clientX-offsetValue.left+17;
            var y = e.clientY-15;
            //将拖拽后需用到值放到拖拽元素新建属性上
            var thValue = $(this).find(".thListValue").text();
            var tdValue = $(this).find(".tdListValue").text();
            var typeValue = $(this).attr('_type');
            //鼠标移动时在鼠标上显示的内容效果
            var text = $(this).text();
            var newHtml = "<span id='drafting' style='position: absolute'>"+text+"</span>";
            $(newHtml).appendTo($(".modal-content"));
            //拖动鼠标在固定区域样式
            $(".modal-content").css('cursor','move');
            $("#drafting").css({'left': x,'top': y});
            $("#drafting").attr('thNewValue',thValue);
            $("#drafting").attr('tdNewValue',tdValue);
            $("#drafting").attr('typeNewValue',typeValue);
        });
        $(document).mousemove(function(e){
            var offsetValue = $(".selectListC").offset();
            var x = e.clientX-offsetValue.left+17;
            var y = e.clientY-15;
            if($("#drafting").length>0){
                $("#drafting").css({'left': x,'top': y});
            }
        });
        $(document).mouseup(function(e){
            $("#drafting").remove();
            $(".modal-content").css('cursor','auto');
        });
        //鼠标移动到表格抬起时进行的操作
        $(".tableChild" ).mouseup(function(e){
            var jsonObject = tableChild.getOperationThisCell();
            var value = jsonObject.value,
                colclassname = jsonObject.colclassname,
                index = jsonObject.index,
                id = jsonObject.id;
            var tdColclassname = $("#drafting").attr('tdNewValue');
            var thColname = $("#drafting").attr('thNewValue');
            value = tdColclassname;
            var newColclassname = tdColclassname;
            if(newColclassname){
                //改变表头数据和colclassname
                var isRepetition = tableChild.setColNewValue(colclassname,newColclassname,thColname);
                var isIdIndex;
                if(isRepetition == 'true'){
                    //改变单元格数据
                    if(id){
                        isIdIndex = id;
                    }else{
                        isIdIndex = index;
                    }
                    var valueContent = new Object();
                    valueContent[newColclassname] = value;
                    var tdValue = new Object();
                    tdValue[isIdIndex] = valueContent;
                    tableChild.setColDataInfo(tdValue);
                 }else{
                    alert("列重复，请重新选择！！");
                 }
             }
            var listType = $("#drafting").attr('typeNewValue');
            if(listType == 'datetime'){
                tableChild.setEditCol([newColclassname],'date');
            }else{
                tableChild.setEditCol([newColclassname]);
            }
            //设置"0"行不能编辑
            tableChild.setZeroEditCancel();
        });

        //通过点击单元格来确定按钮是否激活函数
        var changeBtn = function(obj,className){
            var jsonObjectSelect = tableChild.getSelectCellobjs();
            var selectLength = jsonObjectSelect.length;
            var isActive = obj.hasClass('active');
            if(selectLength == 1){
                var isClassInCell,
                    isIdIndex;
                var colClassName = jsonObjectSelect[0].colclassname;
                if (jsonObjectSelect[0].id) {
                    isIdIndex = jsonObjectSelect[0].id;
                } else {
                    isIdIndex = jsonObjectSelect[0].index;
                }
                isClassInCell = tableChild.IsClassInCell(colClassName, isIdIndex, className);
                if(isClassInCell == 'true'){
                    obj.addClass('active');
                }else{
                    obj.removeClass('active');
                }
            }else if(selectLength == 0){
                if(isActive){
                    obj.removeClass('active');
                }
            }
        };
        //通过点击按钮来改变以类定义的样式函数
        var addTableStyle = function(obj,className){
            var jsonObjectSelect = tableChild.getSelectCellobjs();
            var selectLength = jsonObjectSelect.length;
            var isIdIndex;
            var isActive = obj.hasClass('active');
            if(isActive){
                for(var i=0 ; i<selectLength ; i++){
                    var colClassName = jsonObjectSelect[i].colclassname;
                    if(jsonObjectSelect[i].id){
                        isIdIndex = jsonObjectSelect[i].id;
                    }else{
                        isIdIndex = jsonObjectSelect[i].index;
                    }
                    tableChild.removeClassCell(colClassName,isIdIndex,className);
                    obj.removeClass('active');
                }
            }else{
                for(var i=0 ; i<selectLength ; i++){
                    var colClassName = jsonObjectSelect[i].colclassname;
                    if(jsonObjectSelect[i].id){
                        isIdIndex = jsonObjectSelect[i].id;
                    }else{
                        isIdIndex = jsonObjectSelect[i].index;
                    }
                    tableChild.setClassInCell(colClassName,isIdIndex,className);
                    obj.addClass('active');
                }
            }
        };
        //判断文字排版的按钮激活样式
        var changeTextAlign = function(){
            var isClassInCellLeft,
                isClassInCellRight,
                colClassName,
                isIdIndex;
            var jsonObjectSelect = tableChild.getSelectCellobjs();
            var selectLength = jsonObjectSelect.length;
            var length = selectLength-1;
            if(length < 0){
                $(".align_left").removeClass('active');
                $(".align_center").removeClass('active');
                $(".align_right").removeClass('active');
            }else{
                if(jsonObjectSelect[length].id){
                    isIdIndex = jsonObjectSelect[length].id;
                }else{
                    isIdIndex = jsonObjectSelect[length].index;
                }
                colClassName = jsonObjectSelect[length].colclassname;
                isClassInCellLeft = tableChild.IsClassInCell(colClassName,isIdIndex,'tableChild_align_left');
                isClassInCellRight = tableChild.IsClassInCell(colClassName,isIdIndex,'tableChild_align_right');
                if(isClassInCellLeft == 'true'){
                    var isLeftActive = $(".align_left").hasClass('active');
                    if(isLeftActive){
                        $(".align_left").removeClass('active');
                    }else{
                        $(".align_left").addClass('active');
                        $(".align_right").removeClass('active');
                        $(".align_center").removeClass('active');
                    }
                }else if(isClassInCellRight == 'true'){
                    var isRightActive = $(".align_right").hasClass('active');
                    if(isRightActive){
                        $(".align_right").removeClass('active');
                    }else{
                        $(".align_right").addClass('active');
                        $(".align_center").removeClass('active');
                        $(".align_left").removeClass('active');
                    }
                }else{
                    tableChild.setClassInCell(colClassName,isIdIndex,'tableChild_align_center');
                    $(".align_center").addClass('active');
                    $(".align_left").removeClass('active');
                    $(".align_right").removeClass('active');
                }
            }
        };
        //判断按钮是否是禁用状态
        var isDisabled = function(){
            var jsonObjectSelect = tableChild.getSelectCellobjs();
            var selectLength = jsonObjectSelect.length;
            if(selectLength == 0){
                $('.leftCol').addClass('disabled');
                $('.removeCol').addClass('disabled');
            }else{
                $('.leftCol').removeClass('disabled');
                $('.removeCol').removeClass('disabled');
            }
        };
        //表格单元格监听事件
        tableChild.AddCellClick(function(){
            var font_bold = $(".font_bold"),
                tableChild_font_bold = 'tableChild_font_bold';
            changeBtn(font_bold,tableChild_font_bold);
            var font_italic = $(".font_italic"),
                tableChild_font_italic = 'tableChild_font_italic';
            changeBtn(font_italic,tableChild_font_italic);
            var text_decoration = $(".text_decoration"),
                tableChild_text_decoration = 'tableChild_text_decoration';
            changeBtn(text_decoration,tableChild_text_decoration);
            var bulge = $(".bulge"),
                tableChild_bulge = 'tableChild_bulge';
            changeBtn(bulge,tableChild_bulge);
            var lineWrap = $(".lineWrap"),
                tableChild_lineWrap = 'tableChild_lineWrap';
            changeBtn(lineWrap,tableChild_lineWrap);

            changeTextAlign();
            isDisabled();
        });
        //样式按钮改变样式
        $(".font_bold").click(function () {
            var obj = $(".font_bold"),
                className = 'tableChild_font_bold';
            addTableStyle(obj,className);
        });
        $(".font_italic").click(function(){
            var font_italic = $(".font_italic"),
                tableChild_font_italic = 'tableChild_font_italic';
            addTableStyle(font_italic,tableChild_font_italic);
        });
        $(".text_decoration").click(function(){
            var text_decoration = $(".text_decoration"),
                tableChild_text_decoration = 'tableChild_text_decoration';
            addTableStyle(text_decoration,tableChild_text_decoration);
        });
        //工具栏中个别工具按钮下拉效果
        var changeFontFlag = true,
            changeFontSizeFlag = true;
        $(".changeFont").click(function(){
            if(changeFontFlag){
                $(".changeFontC").css('display','block');
                changeFontFlag = false;
            }else{
                $(".changeFontC").css('display','none');
                changeFontFlag = true;
            }
        });
        $(".changeFontSize").click(function(){
            if(changeFontSizeFlag){
                $(".changeFontSizeC").css('display','block');
                changeFontSizeFlag = false;
            }else{
                $(".changeFontSizeC").css('display','none');
                changeFontSizeFlag = true;
            }
        })
        //字体与字号表现形式
        var fontSizeInUl = {fontInUl:["宋体","黑体","楷体"],sizeInUl:['1','2','3']};
        var fontInUlLength = fontSizeInUl.fontInUl.length,
            sizeInUlLength = fontSizeInUl.sizeInUl.length;
        for(var i=0 ;i<fontInUlLength;i++){
            $(".changeFontC ul").append('<li>'+fontSizeInUl.fontInUl[i]+'</li>');
            $(".changeFontC ul li").css('padding','5px 0');
        }
        for(var i=0;i<sizeInUlLength;i++){
            $(".changeFontSizeC ul").append('<li style="padding:5px 0;">'+fontSizeInUl.sizeInUl[i]+'</li>');
        }
        //工具栏中个别具有下拉按钮效果操作
        var textVerticalFlag = true;
        var textVerticalDiv = function(){
            $(".textVerticalC").css('display','none');
                textVerticalFlag = true;
                $(".textVertical").css({'border':'none','padding':'2px 8px'});
        }
        $(".textVertical").click(function(){
            if(textVerticalFlag){
                $(".textVerticalC").css('display','block');
                textVerticalFlag = false;
                $(".textVertical").css({'border':'1px solid #ccc','padding':'1px 7px 2px','border-bottom':'none'});
                $(".changeMoreC").css('display','none');
                $(".changeMore").css('border','none');
                changeFlag = true;
            }else{
                textVerticalDiv();
            }
        });
        $(".vertical_top").click(function(){
            textVerticalDiv();
        });
        $(".vertical_middle").click(function(){
            textVerticalDiv();
        });
        $(".vertical_bottom").click(function(){
            textVerticalDiv();
        });

        var tableBorderFlag = true;
        //var tableBorderSelected = $(".tableBorderSelected span").text();
        //$(".tableBorderShow").text(tableBorderSelected);
        var tableBorderDiv = function(){
            $(".tableBorderC").css('display','none');
                tableBorderFlag = true;
                $(".tableBorder").css({"border":"none","padding":"2px 8px"});
        }
        $(".tableBorder").click(function(){
            if(tableBorderFlag){
                $(".tableBorderC").css('display','block');
                tableBorderFlag = false;
                $(".tableBorder").css({"border":"1px solid #ccc","padding":"1px 7px 2px","border-bottom":"none"});
            }else{
                tableBorderDiv();
            }
        })
        
        var changeFlag = true;
        var changeMoreDiv = function(){
            $(".changeMoreC").css('display','none');
                changeFlag = true;
                $(".changeMore").css({'border':'none','padding':'2px 8px'});
        };
        $(".changeMore").click(function(){
            if(changeFlag){
                $(".changeMoreC").css('display','block');
                changeFlag = false;
                $(".changeMore").css({'border':'1px solid #ccc','padding':'1px 7px 2px','border-bottom':'none'});
                $(".textVerticalC").css('display','none');
                $(".textVertical").css('border','none');
                textVerticalFlag = true;
            }else{
                changeMoreDiv();
            }
        });
        $(".bulge").click(function(){
            changeMoreDiv();
            var bulge = $(".bulge"),
                tableChild_bulge = 'tableChild_bulge';
            addTableStyle(bulge,tableChild_bulge);
        });
        $(".lineWrap").click(function(){
            changeMoreDiv();
            var lineWrap = $(".lineWrap"),
                tableChild_lineWrap = 'tableChild_lineWrap';
            addTableStyle(lineWrap,tableChild_lineWrap);
        });
        //文字排版：情况复杂，待定
        $(".writing_mode").click(function(){
            changeMoreDiv();
            var jsonObjectSelect = tableChild.getSelectCellobjs();
            var selectLength = jsonObjectSelect.length;
            var btnText = $(".writing_mode span").text();
            if(btnText == "竖向文字"){
                var tdText ="";
                for(var i=0;i<selectLength;i++){
                    var values = jsonObjectSelect[i].value;
                    var  length = values.length;
                    for(var j=0;j<length;j++){
                        var value = values.charAt(j);
                        tdText+=value+'<br>';
                    }
                    values = tdText;
                    var index = jsonObjectSelect[i].index,
                        newClassName = jsonObjectSelect[i].colclassname;
                    var valueContent = new Object();
                    valueContent[newClassName] = values;
                    var tdValue = new Object();
                    tdValue[index] = valueContent;
                    tableChild.setHtmlColByIndex(tdValue);
                }
                $(".writing_mode span").text('横向文字');
            }else{
                $(".writing_mode span").text('竖向文字');
            }

        });
        //文本排版方式操作
        $(".align_left").click(function(){
           var jsonObjectSelect = tableChild.getSelectCellobjs();
           var selectLength = jsonObjectSelect.length;
           var isIdIndex;
                for(var i=0;i<selectLength;i++) {
                    var colClassName = jsonObjectSelect[i].colclassname;
                    if (jsonObjectSelect[i].id) {
                        isIdIndex = jsonObjectSelect[i].id;
                    } else {
                        isIdIndex = jsonObjectSelect[i].index;
                    }
                    tableChild.setClassInCell(colClassName, isIdIndex, 'tableChild_align_left');
                    $(".align_left").addClass('active');
                    tableChild.removeClassCell(colClassName,isIdIndex,'tableChild_align_right');
                    $(".align_right").removeClass('active');
                    tableChild.removeClassCell(colClassName,isIdIndex,'tableChild_align_center');
                    $(".align_center").removeClass('active');
                }
       });
        $(".align_right").click(function(){
            var jsonObjectSelect = tableChild.getSelectCellobjs();
            var selectLength = jsonObjectSelect.length;
            var isIdIndex;
            for(var i=0;i<selectLength;i++) {
                var colClassName = jsonObjectSelect[i].colclassname;
                if (jsonObjectSelect[i].id) {
                    isIdIndex = jsonObjectSelect[i].id;
                } else {
                    isIdIndex = jsonObjectSelect[i].index;
                }
                tableChild.setClassInCell(colClassName, isIdIndex, 'tableChild_align_right');
                $(".align_right").addClass('active');
                tableChild.removeClassCell(colClassName,isIdIndex,'tableChild_align_left');
                $(".align_left").removeClass('active');
                tableChild.removeClassCell(colClassName,isIdIndex,'tableChild_align_center');
                $(".align_center").removeClass('active');
            }
        });
        $(".align_center").click(function(){
            var jsonObjectSelect = tableChild.getSelectCellobjs();
            var selectLength = jsonObjectSelect.length;
            var isIdIndex;
            for(var i=0;i<selectLength;i++) {
                var colClassName = jsonObjectSelect[i].colclassname;
                if (jsonObjectSelect[i].id) {
                    isIdIndex = jsonObjectSelect[i].id;
                } else {
                    isIdIndex = jsonObjectSelect[i].index;
                }
                tableChild.setClassInCell(colClassName, isIdIndex, 'tableChild_align_center');
                $(".align_center").addClass('active');
                tableChild.removeClassCell(colClassName,isIdIndex,'tableChild_align_right');
                $(".align_right").removeClass('active');
                tableChild.removeClassCell(colClassName,isIdIndex,'tableChild_align_left');
                $(".align_left").removeClass('active');
            }
        });

        //多行表头上插行操作
        $(".upRow").click(function(){
            var titleIndex = tableChild.getActiveTitle();
            tableChild.insertTitletoTable(titleIndex,1);
        });
        //多行表头下插行操作
        $(".downRow").click(function(){
            var titleIndex = tableChild.getActiveTitle();
            tableChild.insertTitletoTable(titleIndex-1,1);
        });
        //多行表头移行操作
        $(".removeRow").click(function(){
            var indexTitle = tableChild.getActiveTitle();
            tableChild.deleteTitle(indexTitle);
        });
        //多行表头合并单元格操作
        $(".mergeCell").click(function(){
            var jsonObject = tableChild.getSelectCellTitle();
            var selectLength = jsonObject.length;
            if(selectLength>=2){
                for(var i=selectLength-1;i>0;i--){
                    var rowpIndex = jsonObject[i].index;
                    var rownIndex = jsonObject[i-1].index;
                    var colpIndex = jsonObject[i].colindex;
                    var colnIndex = jsonObject[i-1].colindex;
                    var rowAbs = Math.abs(rownIndex-rowpIndex);
                    var colAbs = Math.abs(colnIndex-colpIndex);
                    if(rowAbs == 0 && colAbs == 1){
                        tableChild.mergeTitle(rownIndex,[colpIndex,colnIndex],'');
                    }else{
                        alert("选择的单元格不左右相邻！！");
                    }
                }
            }
        });

        //列操作，根据最后选择的列进行一下操作
        //判断传入变量是否为对象，如不是对象或为空，则返回为true；
        var isEmptyObject = function(e){
            var t;
            for(t in e)
               return !1;
            return !0;
        };
        //左插列操作
        $(".leftCol").click(function(){
            var emptyLeft = new Date().getTime();
            var jsonObjectSelect = tableChild.getLastClickObj();
            tableChild.insertColforClass(jsonObjectSelect.colclassname, [{"classname": emptyLeft,"classtext": ""}], "before");
            $(".colWidth").val('140');
        });
        //右插列操作
        $(".rightCol").click(function(){
            var emptyRight = new Date().getTime();
            var jsonObjectSelect = tableChild.getLastClickObj();
            if(isEmptyObject(jsonObjectSelect)) {
                tableChild.insertColforClass('',[{"classname":emptyRight,"classtext":""}]);
                $(".colWidth").val('140');
            }else{
                tableChild.insertColforClass(jsonObjectSelect.colclassname,[{"classname":emptyRight,"classtext":""}]);
            }
        });
        //移列操作
        $(".removeCol").click(function(){
            var jsonObjectSelect = tableChild.getLastClickObj();
            tableChild.removeColByClass([jsonObjectSelect.colclassname]);
            $('.btn').removeClass('active');
        });

        //单元格编辑宽高样式号
        var colRowJ = function(obj,event){
            event = window.event || event;
            if(event.keyCode == 37 || event.keyCode == 39){
                return;
            }
            obj.value = obj.value.replace(/[^0-9]/g, '');
        };
        //列数填值进行操作
        $(".colNumber").keyup(function(){
            colRowJ(this,event);
            this.value = this.value.replace(/^0/g,'');
            var values = this.value.substr(0,3);
            if(values == '100'){
                this.value = values;
            }else{
                this.value = this.value.substr(0,2);
            }
            //根据输入的值对表格列数进行判断
            //功能包括：当输入值大于表格列数，从最后一列增加缺失列数；当输入值小于表格列数，从最后一列开始删除多余列数
            var valueNumber = parseInt(this.value);
        });
        //列宽输值进行修改
        $(".colWidth").keyup(function (event) {
            colRowJ(this, event);
            var jsonObjectSelect = tableChild.getSelectCellobjs();
            var selectLength = jsonObjectSelect.length;
            for (var i = 0; i < selectLength; i++) {
                if(this.value == '0'){
                    tableChild.removeColByClass([jsonObjectSelect[i].colclassname]);
                }else{
                    tableChild.setWidthCol([{"colclassname":jsonObjectSelect[i].colclassname,"width":this.value}]);
                }
            }
        });

        //颜色选择器配置
        $(".ftCustom").spectrum({
            color:'#000000',
            flat:false,
            showInput:true,
            showInitial:true,
            allowEmpty:true,
            showAlpha:true,
            showPaletteOnly: true,
            hideAfterPaletteSelect:true,
            togglePaletteOnly: true,
            cancelText: "取消",
            chooseText:"确定",
            togglePaletteMoreText: "自定义颜色",
            togglePaletteLessText: "隐藏自定义",
            containerClassName: "contColor",
            replacerClassName: "ftRepColor",
            preferredFormat: "rgb",
            palette: [
                ["#000","#444","#666","#999","#ccc","#eee","#f3f3f3","#fff"],
                ["#f00","#f90","#ff0","#0f0","#0ff","#00f","#90f","#f0f"],
                ["#f4cccc","#fce5cd","#fff2cc","#d9ead3","#d0e0e3","#cfe2f3","#d9d2e9","#ead1dc"],
                ["#ea9999","#f9cb9c","#ffe599","#b6d7a8","#a2c4c9","#9fc5e8","#b4a7d6","#d5a6bd"],
                ["#e06666","#f6b26b","#ffd966","#93c47d","#76a5af","#6fa8dc","#8e7cc3","#c27ba0"],
                ["#c00","#e69138","#f1c232","#6aa84f","#45818e","#3d85c6","#674ea7","#a64d79"],
                ["#900","#b45f06","#bf9000","#38761d","#134f5c","#0b5394","#351c75","#741b47"],
                ["#600","#783f04","#7f6000","#274e13","#0c343d","#073763","#20124d","#4c1130"]
            ],
            clearText:"清除颜色",
            noColorSelectedText:"透明",
            showButtons:true,
        });
        $(".bgCustom").spectrum({
            color:'#000000',
            flat:false,
            showInput:true,
            showInitial:true,
            allowEmpty:true,
            showAlpha:true,
            showPaletteOnly: true,
            hideAfterPaletteSelect:true,
            togglePaletteOnly: true,
            cancelText: "取消",
            chooseText:"确定",
            togglePaletteMoreText: "自定义颜色",
            togglePaletteLessText: "隐藏自定义",
            containerClassName: "contColor",
            replacerClassName: "bgRepColor",
            preferredFormat: "rgb",
            palette: [
                ["#000","#444","#666","#999","#ccc","#eee","#f3f3f3","#fff"],
                ["#f00","#f90","#ff0","#0f0","#0ff","#00f","#90f","#f0f"],
                ["#f4cccc","#fce5cd","#fff2cc","#d9ead3","#d0e0e3","#cfe2f3","#d9d2e9","#ead1dc"],
                ["#ea9999","#f9cb9c","#ffe599","#b6d7a8","#a2c4c9","#9fc5e8","#b4a7d6","#d5a6bd"],
                ["#e06666","#f6b26b","#ffd966","#93c47d","#76a5af","#6fa8dc","#8e7cc3","#c27ba0"],
                ["#c00","#e69138","#f1c232","#6aa84f","#45818e","#3d85c6","#674ea7","#a64d79"],
                ["#900","#b45f06","#bf9000","#38761d","#134f5c","#0b5394","#351c75","#741b47"],
                ["#600","#783f04","#7f6000","#274e13","#0c343d","#073763","#20124d","#4c1130"]
            ],
            clearText:"清除颜色",
            noColorSelectedText:"透明",
            showButtons:true,
        });
        $(".contColor").find('.sp-input-container').css({'width':'170px','float':'none'});
        $(".ftRepColor").addClass('btn btn-default').removeClass('sp-light sp-replacer').css({'padding':'2px 8px','border':'none'}).attr({'type':'button','title':'文字颜色'}).html('<span class="glyphicon glyphicon-text-color"></span><span class="glyphicon glyphicon-triangle-bottom"></span>');
        $(".bgRepColor").addClass('btn btn-default').removeClass('sp-light sp-replacer').css({'padding':'2px 8px','border':'none'}).attr({'type':'button','title':'单元格背景颜色'}).html('<span>背景</span></span><span class="glyphicon glyphicon-triangle-bottom"></span>');

        //字体颜色配置
        $(".ftCustom").on('change.spectrum',function(e,color){
            var jsonObjectSelect = tableChild.getSelectCellobjs();
            var selectLength = jsonObjectSelect.length;
            var isIdIndex;
            for(var i=0 ; i<selectLength ; i++){
                var colClassName = jsonObjectSelect[i].colclassname;
                if(jsonObjectSelect[i].id){
                    isIdIndex = jsonObjectSelect[i].id;
                }else{
                    isIdIndex = jsonObjectSelect[i].index;
                    }
                tableChild.setStyleInCell(colClassName,isIdIndex,"color:"+color+";");
            }
        });
        //背景颜色配置
        $(".bgCustom").on('change.spectrum',function(e,color){
            var jsonObjectSelect = tableChild.getSelectCellobjs();
            var selectLength = jsonObjectSelect.length;
            var isIdIndex;
            for(var i=0 ; i<selectLength ; i++){
                var colClassName = jsonObjectSelect[i].colclassname;
                if(jsonObjectSelect[i].id){
                    isIdIndex = jsonObjectSelect[i].id;
                }else{
                    isIdIndex = jsonObjectSelect[i].index;
                    }
                tableChild.setStyleInCell(colClassName,isIdIndex,"background-color:"+color+";");
            }
        });

    },

    _getContentData : function(parentDom){
        return {tableData : $(parentDom).find(".tableChild").toCreateZcTable({}).getSerialize(),selectTableAttr:$(parentDom).find("#selectList .listSelected").attr('_name')};
    },

    getID : function(){
        return BCP.bill.modalRenderer.SubtableModalRenderer.ID;
    }
    
});